//
//  CompletionCell.m
//  wtshoppingcite
//
//  Created by TW on 14-12-11.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "CompletionCell.h"

@implementation CompletionCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 100, 80)];
    [self.contentView addSubview:_iconImage];
    
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconImage.right + 8, _iconImage.top, kWidth-120, 40)];
    _titleLabel.font = [UIFont systemFontOfSize:16.0f];
    _titleLabel.numberOfLines = 0;
    _titleLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_titleLabel];
    
    
    _iconImageTotal = [[UIImageView alloc]initWithFrame:CGRectMake(_titleLabel.left, _titleLabel.bottom +10, 7, 6)];
    _iconImageTotal.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_iconImageTotal];
    
    
    _totalNumLabel = [[UILabel alloc]initWithFrame:CGRectMake(_iconImageTotal.right, _titleLabel.bottom, 40, 22)];
    _totalNumLabel.font = [UIFont systemFontOfSize:14.0f];
    _totalNumLabel.textColor = [UIColor lightGrayColor];
    _totalNumLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_totalNumLabel];
    
    
    _countNumLabel = [[UILabel alloc]initWithFrame:CGRectMake(_totalNumLabel.right + 3, _totalNumLabel.top, 40, 22)];
    _countNumLabel.textColor = [UIColor lightGrayColor];
    _countNumLabel.right = kWidth - 15;
    _countNumLabel.textAlignment = NSTextAlignmentRight;
    _countNumLabel.font = [UIFont systemFontOfSize:14.0f];
    [self.contentView addSubview:_countNumLabel];
    
    _countLabel = [[UILabel alloc]initWithFrame:CGRectMake(_totalNumLabel.right + 3, _totalNumLabel.top, 40, 22)];
    _countLabel.text = @"数量:";
    _countLabel.right = _countNumLabel.left+10;
    _countLabel.font = [UIFont systemFontOfSize:14.0f];
    _countLabel.textColor = [UIColor lightGrayColor];
    _countLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_countLabel];
    
    _payOrder = [[UIButton alloc]initWithFrame:CGRectMake(0, _countNumLabel.bottom +2, 68, 25)];
    _payOrder.right = kWidth - 10;
    [_payOrder setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_payOrder setFont:[UIFont systemFontOfSize:12.0f]];
    [_payOrder setTitle:@"评价订单" forState:UIControlStateNormal];
    [_payOrder setBackgroundImage:[UIImage imageNamed:@"register_select"] forState:UIControlStateNormal];
    [_payOrder addTarget:self action:@selector(commentAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_payOrder];
    
    
    _cancelOrder = [[UIButton alloc]initWithFrame:CGRectMake(0,_countNumLabel.bottom +2, 68, 25)];
    _cancelOrder.right = _payOrder.left - 10;
    [_cancelOrder setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_cancelOrder setFont:[UIFont systemFontOfSize:12.0f]];
    [_cancelOrder setTitle:@"删除订单" forState:UIControlStateNormal];
    [_cancelOrder setBackgroundImage:[UIImage imageNamed:@"register_select"] forState:UIControlStateNormal];
    [_cancelOrder addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_cancelOrder];

}

-(void)setMyOrderModel:(MyOrderModel *)myOrderModel{
    
    if (_myOrderModel != myOrderModel) {
        
        _myOrderModel = myOrderModel;
        
        MyOrderItems *myOrderItems = [[MyOrderItems alloc]initWithMyOrderItemInfo:[myOrderModel.orderItems objectAtIndex:0]];
        
        [_iconImage setImageWithURL:[NSURL URLWithString:myOrderItems.mainImgPath] placeholderImage:[UIImage imageNamed:@"all_defalutImage"]];
        _titleLabel.text = myOrderItems.descp;
        _totalNumLabel.text = myOrderItems.salePrice;
        _countNumLabel.text = myOrderItems.count;
        [_iconImageTotal setImage:[UIImage imageNamed:@"register_money.png"]];
    }
}

-(void)cancelAction:(UIButton*)button{
    
    
    if([self.delegate respondsToSelector:@selector(cancelCell:)]){
        [self.delegate cancelCell:self.myOrderModel];
    }
}



-(void)commentAction:(UIButton*)button{
    
    if([self.delegate respondsToSelector:@selector(commentCell:)]){
        [self.delegate commentCell:self.myOrderModel];
    }
}

@end
